﻿

function FacebookMesajGonder(baslik, mesaj,resim,link,aciklama, username, token) {
    //message, picture, link, name, caption, description, source
    var json = { caption: baslik, message: mesaj,picture:resim,link:link,description:aciklama };
    $.ajax({
        type: "post",
        url: "https://graph.facebook.com/" + username + "/feed?access_token=" + token + "&message=" + encodeURI(mesaj) + "&picture=" + encodeURI(resim) + "&link=" + link + "&description=" + aciklama,
        data: $.toJSON(json),
        dataType: "json",
        success: function (data) {
            alert(data.id); 
        }
    });

}


function parametreGetir(key, default_) {
    if (default_ == null) default_ = "";
    key = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regex = new RegExp("[\\?&]" + key + "=([^&#]*)");
    var qs = regex.exec(window.location.href);
    if (qs == null)
        return default_;
    else
        return qs[1];
}

function hataver(xhr, status, error) {
    var err = eval("(" + xhr.responseText + ")");
    $('#hata').empty();
    $('#hata').append(err.Message);
    if (err.Message == 'Authentication failed.') {
        pathArray = window.location.pathname.split('/');
        host = pathArray[2];


        window.location = "http://"+window.location.host + "/error.aspx?err='geberik error'";
        //window.location.hostname
    }
    $('#hata').dialog({
        modal: true,
        width: 450,
        buttons: {
            "Kapat": function () {
                $(this).dialog("close");
            }
        }
    });
};

function mesajVer(mesaj) {
    $('#hata').empty();
    $('#hata').append(mesaj);
    $('#hata').dialog({
        modal: true,
        width: 450,
        buttons: {
            "Kapat": function () {
                $(this).dialog("close");
            }
        }
    });
}

function dialogMesaj(title, mesaj, buttons,onClose) {
    $('#dial').empty();
    $('#dial').append(mesaj);
    if (onClose) {
        $('#dial').dialog({
            title: title,
            modal: true,
            buttons: buttons,
            close:onClose
        });
    } else {
        $('#dial').dialog({
            title: title,
            modal: true,
            buttons: buttons
        });
    }
}



function ekranKilitle(mesaj, div) {
    if (!div) {
        div = "kilit";
    }
    $('div.'+div).block({
        theme: true,
        message: mesaj,
        css: { border: '3px solid #a00' }
    });
}
function ekranAc(div) {
    if (!div) {
        div = "kilit";
    }
    $('div.'+div).unblock();
}
function ekranAcAnket(div) {
    if (!div) {
        div = "kilit";
    }
    $('body').unblock();
}
function ajaxCalistir(json, adr, succ) {
    ekranKilitle("Lütfen Bekleyiniz");
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url:adr,
        data: $.toJSON(json),
        dataType: "json",
        success: succ,
        timeout:36000000,
        error: function (xhr,data, textStatus) {
            ekranAc();
            hataver(xhr, status, Error);
        }
    });
}

function ajaxCalistirAnket(json, adr, succ) {
    $('body').block({
        theme: true,
        message: 'Lütfen Bekleyiniz.',
        css: { border: '3px solid #a00' }
    });
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: adr,
        data: $.toJSON(json),
        dataType: "json",
        success: succ,
        error: function (xhr, data, textStatus) {
            ekranAc();
            hataver(xhr, status, Error);
        }
    });
}
function fqlCalistir(qry,token,succ) {
    ekranKilitle("Facebook Komutu Çalıştırılıyor, Lütfen Bekleyiniz");
    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: 'https://api.facebook.com/method/fql.query?query=' + qry + '&access_token=' + encodeURI(token) + '&format=json',
        dataType: "jsonp",
        success: succ,
        error: function (xhr, data, textStatus) {
            ekranAc();
            hataver(xhr, status, Error);
        }
    });
}